package com.rr.controller;

import com.rr.entity.AddAction;
import com.rr.entity.UpdateAction;
import com.rr.event.AddActionEvent;
import com.rr.event.BaseEvent;
import com.rr.event.UpdateActionEvent;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/action")
@RequiredArgsConstructor
public class ActionController {

    private final ApplicationEventPublisher applicationEventPublisher;

    @PostMapping("/add")
    public String addNew() {
        applicationEventPublisher.publishEvent(new BaseEvent<>(new AddAction()));
        return "操作成功";
    }

    @PostMapping("/update")
    public String updateNew() {
        applicationEventPublisher.publishEvent(new BaseEvent<>(new UpdateAction()));
        return "操作成功";
    }
}
